package com.hdax.dmw.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dmw.common.utils.Result;
import com.hdax.dmw.common.utils.ResultGenerator;
import com.hdax.dmw.entity.item.Item;
import com.hdax.dmw.item.dtos.HotItemsDto;
import com.hdax.dmw.item.dtos.ItemDescDto;
import com.hdax.dmw.item.mapstruct.HotItemDtoMapper;
import com.hdax.dmw.item.mapstruct.ItemDescDtoMapper;
import com.hdax.dmw.item.service.ItemService;
import com.hdax.dmw.item.mappers.ItemMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author guoyisha
* @description 针对表【dm_item(节目表)】的数据库操作Service实现
* @createDate 2023-06-18 14:55:02
*/
@Service
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item>
    implements ItemService{

    @Autowired
    private HotItemDtoMapper dtoMapper;

    @Override
    public List<HotItemsDto> hotItems(Long itemType1Id) {
        QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
        //1. 必须热门 isRecommend
        queryWrapper.eq("isRecommend",1);
        //2. 某个分类
        queryWrapper.eq("itemType1Id",itemType1Id);
        //3. 演出时间降序  order by startTime desc
        queryWrapper.orderByDesc("startTime");
        //4. 前5个  limit 5
        queryWrapper.last("limit 5");
        List<HotItemsDto> dtos = new ArrayList<>();
        List<Item> list = list(queryWrapper);
        dtos = dtoMapper.toTargetList(list);
        return dtos;
    }

    @Autowired
    private ItemDescDtoMapper descDtoMapper;

    @Override
    public Result<ItemDescDto> getItems(Long itemId) {
        //Item item = getById(itemId);
        Item item = baseMapper.getItems(itemId);
        ItemDescDto dto = descDtoMapper.toTarget(item);
        return ResultGenerator.genSuccessResult(dto);
    }
}




